#region License
/* ---------------------------------------------------------------- *
 *
 * This file is part of the Xcoordination Application Space
 * ("XcoAppSpace") http://www.xcoordination.com
 *
 * Copyright (C) 2009 Xcoordination http://www.xcoordination.com
 *
 * XcoAppSpace is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General
 * Public License as published by the Free Software Foundation.
 *
 * XcoAppSpace is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/
 * or write to the Free Software Foundation, Inc., 51 Franklin
 * Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * ---------------------------------------------------------------- */
#endregion

using System;
using System.ServiceModel;
using XcoAppSpaces.Contracts.Logging;
using Microsoft.ServiceBus;

namespace XcoAppSpaces.Transport.WCF
{
    /// <summary>
    /// Sender for communication with remote spaces. Uses an IRemoteSpaceService to communicate
    /// with service hosts of remote spaces.
    /// </summary>
    public class RemoteSenderAzure : RemoteSender
    {
        private static ChannelFactory<SpaceServiceChannel> LoadConfiguration(string addr)
        {
            ChannelFactory<SpaceServiceChannel> channelFactory = new ChannelFactory<SpaceServiceChannel>("XcoClient", new EndpointAddress(addr));
            return channelFactory;
        }


        /// <summary>
        /// Creates a new RemoteSender. A new IRemoteSpaceService object is created that communicates
        /// with the given address, with help of the ChannelFactory class.
        /// </summary>
        /// <param name="address">The address of the remote space, in binding form.</param>
        /// <param name="log">Logger to use for logging.</param>
        /// <param name="shutdown">Shutdown event for faster cleanup</param>
		public RemoteSenderAzure(string address, IXcoLogger log,IXcoWCFTransportSessionShutdown shutdown)
            : base(address, new LoadConfigurationDelegate(LoadConfiguration),log, shutdown, new BindingsHelperAzure())
        {
        }

        /// <summary>
        /// Creates a new RemoteSender. A new IRemoteSpaceService object is created that communicates
        /// with the given address, with help of the ChannelFactory class.
        /// </summary>
        /// <param name="address">The address of the remote space, in binding form.</param>
        /// <param name="loadConfig">Delegate for loading the service configuration.</param>
         /// <param name="log">Logger to use for logging.</param>
        /// <param name="shutdown">Shutdown event for faster cleanup</param>
        public RemoteSenderAzure(string address, LoadConfigurationDelegate loadConfig, IXcoLogger log,IXcoWCFTransportSessionShutdown shutdown)
			: base(address, loadConfig, log, shutdown, new BindingsHelperAzure())
        {
        }
        
      /*  public  void Connect()
        {
            spaceService.Connect();
      
            IHybridConnectionStatus hybridConnectionStatus = spaceService.GetProperty<IHybridConnectionStatus>();
            hybridConnectionStatus.ConnectionStateChanged += (o, e) =>
            {
                Console.WriteLine("Upgraded!");
            };
        }*/
    }
}
